#{extends 'adminm/frame.html' /}

#{set 'moreScripts'}
<script src="@{'/public/javascripts/jquery-ui-1.8.10.custom.min.js'}" type="text/javascript" charset="utf-8"></script>
<script src="@{'/public/pager/jquery.pager.js'}" type="text/javascript" charset="utf-8"></script>
<script src="@{'/public/ckeditor/ckeditor.js'}" type="text/javascript" charset="utf-8"></script>
<script src="@{'/public/ckeditor/adapters/jquery.js'}" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="@{'/public/uploadify/swfobject.js'}"></script>
<script type="text/javascript" src="@{'/public/uploadify/jquery.uploadify.v2.1.4.min.js'}"></script>
#{/set}
#{set 'moreStyles'}
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/pager/Pager.css'}" />
<link rel="stylesheet" type="text/css" media="screen" href="@{'/public/stylesheets/table.scss'}" />
#{/set}
#{set 'activeItem'}6#{/set}

<div class="navigationBar">
	<table>
		<tr>
			<td><img src="@{'/public/images/navigationHouse.gif'}"></td>
			<td><strong>当前位置：</strong></td>
			<td>
				<a href="/admin">首页</a>
				>>
				<a href="#">文章管理</a>
			</td>
		</tr>
	</table>
</div>

<script language="javascript">

	$(
		function(){
			//初始化创建窗口
			$("#create-form").dialog({autoOpen:false,modal:true,
	        buttons:{提交:function(){createArticle();}}
				})

			//使用ckeditor
			$( 'textarea' ).ckeditor(); 

		}
	);

	$(function(){
		//初始化翻页控件。
		$("#pager").pager(
			{
				pagenumber: ${queryBean.currentPage}, 
				pagecount: ${queryBean.totalPage}, 
				totalcount: ${queryBean.totalQuantity},
				buttonClickCallback: PageClick 
			}
		);
	});
	//翻页功能。
	PageClick = function(pageclickednumber) {
		$("#currentPage").val(pageclickednumber);
		doSearch();
	}

	//打开创建窗口
	function openCreateDialog(){
		$("#create-form").dialog({width:1024});
       $("#create-form").dialog("open");
	}

	//刷新页面
	function doSearch() {
		$("#form1").submit();
	}

	//提交创建信息
	function createArticle() {
		$("#create_form").submit();
	}

	//必填校验
	var required = function(field ,errTip)
	{
		var targetValue = $(field).val();
		if (targetValue == null || targetValue == "")
		{
			alert(errTip);
			return false;	
		}
		else
		{
			return true;
		}
	}

	//删除 文章 
	function removeItem(id) {

		var result = confirm("确实要 删除吗?")
		if(result == false){
			return false;
		}  
		
		$.ajax({
			url: "@{admin.Articles.deleteArticle()}",
			data: "articleIdVal="+id,
			type: "GET",
			complete: function(XMLHttpRequest, textStatus, errorThrown) {
				//获取返回内容并进行解析
				var content = XMLHttpRequest.responseText;
				if("SUCCESS" == content){
					alert("删除成功");
					doSearch();
				}else{
					alert("删除失败");
				}
			}
		});
	}
	
</script>

<div>
	<div class="list_criteria">
		#{form @admin.Articles.queryArticle(), name:'form1', id:'form1'}
		文章标题:
		<input type="text" name="articleTitleVal" id="articleTitleVal" size="10"/>
	    
	    创建者:
	      <input type="text" name="createByAdminVal" id="createByAdminVal" size="10"/>
	        
	     最后修改者:     
	      <input type="text" name="lastModifiedByAdminVal" id="lastModifiedByAdminVal" size="10"/>
           
      <input type="hidden" id="currentPage" name="queryBean.currentPage" value="${queryBean.currentPage}">
	每页
	<select name="queryBean.quantityEachPage" onchange="doSearch()">
		<option value="2" #{if queryBean.quantityEachPage==2} selected #{/if}>2</option>
		<option value="10" #{if queryBean.quantityEachPage==10} selected #{/if}>10</option>
		<option value="25" #{if queryBean.quantityEachPage==25} selected #{/if}>25</option>
		<option value="50" #{if queryBean.quantityEachPage==50} selected #{/if}>50</option>
	</select>
	条记录<br/><br/>
           <input type="submit" value="查询">&nbsp;
	<input type="button" value="添加" onclick="javascript:openCreateDialog();">    
    #{/form}
</div>

<div>
	#{if articleList}  
	<table class="common-table">
		<tr>
			<td>文章ID</td>
			<td>文章标题</td>
			<td>创建日期</td>
			<td>创建者</td>
			<td>最后修改日期</td>
			<td>最后修改者</td>
			<td>操作</td>
		</tr>
		#{list items:articleList, as:'article'}
		<tr>
			<td>${article.id}</td>
			<td>${article.title}</td>
			<td>${article.createAt.format("yyyy-MM-dd hh:mm:ss")}</td>
			<td>${article.createByAdmin?.username}</td>
			<td>${article.lastModifiedAt.format("yyyy-MM-dd hh:mm:ss")}</td>
			<td>${article.lastModifiedByAdmin?.username}</td>
			<td>
				<a class="editer" href="/admin/articles/editArticle?articleIdVal=${article.id}">[修改]</a>&nbsp;
				<a class="editer" href="javascript:removeItem(${article.id})">[删除]</a>&nbsp;
			</td>
		</tr>  		
		#{/list}
	</table>			
	#{/if}
</div>

<!-- 创建窗口 -->
<div id="create-form" class="ui-widget ui-widget-content ui-corner-all" title="创建文章">
    #{form @admin.Articles.createArticle(),id:'create_form'}
    	<div class="list_criteria">
    		标题：<input type="text" name="articleTitleVal_create" id="articleTitleVal_create"></input><br><br>
			 <textarea name="airtcleContentVal_create" id="articleContentVal_create"></textarea>
		</div>
    #{/form}
</div>


<br/>
<div id="pager" style="font-size:1.3em;"></div>
</div>
